<?php
/**
 * 后台入口文件
 */
require('konakona/konakona.php');
k::run();
k::setEncoding('utf-8');

$id = intval($_GET['id']);
$pid = intval($_GET['p']);
$action = !empty($_GET['action'])?$_GET['action']:'login';
if($action != 'login') if(!admin::isAdminOnline())exit;
template::adminTemplatePath();
template::assign('config',k::$config);
k::import( 'helper.page');
error_reporting(E_ALL ^ E_NOTICE);
switch($action){
	case 'guide-add':
	if(isset($_POST['title'])){
			guide::guide_add($_POST);
		}else{
			template::assign('district',district::getDistrict());
			template::display('../admin/guide-add.html');
		}
	break;
	case 'guide-list':
                page::set_Each_page(15);
		template::assign('guide_page',page::run($pid,'guide','admin.php?action=guide-list&p='));
		template::assign('guide_list',guide::guide_list($pid),15);
		template::display('../admin/guide-list.html');
	break;
	case 'guide-del':
		guide::guide_del($id);
	break;
	case 'guide-details':
		template::assign('district',district::getDistrict());
		template::assign('guide_details',guide::guide_details($id));
		template::display('../admin/guide-edit.html');
	break;
	case 'guide-edit':
		guide::guide_edit($_POST);
	break;
	case 'district-add':
		district::district_add($_POST);
	break;
	case 'district-list':
		template::assign('district_list',district::getDistrict());
		template::display('../admin/district-list.html');
	break;
	case 'district-edit':
		district::district_edit($_POST);
	break;
	case 'district-del':
		district::district_del($id);
	break;
	case 'tour-list':
                page::set_Each_page(15);
		template::assign('tour_page',page::run($pid,'tour','admin.php?action=guide-list&p='));
		template::assign('tour_list',tour::tour_list($pid),15);
		template::display('../admin/tour-list.html');
	break;
	case 'tour-add':
		if(isset($_POST['title'])){
			tour::tour_add($_POST);
		}else{
			template::assign('district',district::getDistrict());
			template::display('../admin/tour-add.html');
		}
	break;
	case 'tour-del':
		tour::tour_del($id);
	break;
	case 'tour-details':
		template::assign('district',district::getDistrict());
		template::assign('tour_details',tour::tour_details($id));
		template::display('../admin/tour-edit.html');
	break;
	case 'tour-edit':
		tour::tour_edit($_POST);
	break;
	case 'cate-list':
		template::display('../admin/cate-list.html');
	break;
	case 'reviews-list':
		template::assign('reviews_page',page::run($pid,'tour_reviews','admin.php?action=reviews-list&p='));
		template::assign('reviews_list',reviews::reviews_list($pid));
		template::display('../admin/reviews-list.html');
	break;
	case 'reviews-add':
		if($_POST['reviews_name']!='' && $_POST['reviews_content']!=''){
			reviews::reviews_add($_POST);
		}else{
			template::assign('tour_title',tour::getTitle($id));
			template::assign('id',$id);
			template::display('../admin/reviews-add.html');
		}
	break;
	case 'reviews-details':
		template::assign('id',$id);
		template::assign('reviews_details',reviews::reviews_details($id));
		template::display('../admin/reviews-edit.html');
	break;
	//反馈图片单张删除
	case 'reviews-pic-del':
		reviews::reviews_pic_del($_GET['pic']);
	break;
	//反馈编辑
	case 'reviews-edit':
		reviews::reviews_edit();
	break;
	case 'reviews-del':
		reviews::reviews_del($id);
	break;
	case 'upload':
		$ImageDir =  "pic/";
		$tmp_name = md5($_FILES['upload']['name'].time()).substr($_FILES['upload']['name'],-4,4);
		if(copy($_FILES['upload']['tmp_name'],$ImageDir.$tmp_name)){
			echo "<script>alert('上传成功!');</script>";
			echo "图片地址 {$ImageDir}{$tmp_name}";
		}else{
			echo "<script>alert('上传失败，请联系技术员');</script>";
			echo "技术员MSN:kona.kona@hotmail.com";
		}
	break;
	case 'browse':
		//显示所有pic的图片
	break;
	case 'news-add':
		if(isset($_POST['title'])){
			news::news_add($_POST);
		}
		template::display('../admin/news-add.html');
	break;
	case 'news-list':
                page::set_Each_page(15);
		template::assign('news_page',page::run($pid,'news','admin.php?action=news-list&p='));
		template::assign('news_list',news::news_list($pid,15));
		template::display('../admin/news-list.html');
	break;
	case 'news-del':
		news::news_del($id);
	break;
	case 'news-details':
		template::assign('news_details',news::news_details($id));
		template::display('../admin/news-edit.html');
	break;
	case 'news-edit':
		news::news_edit($_POST);
	break;
	case 'order-tour-list':
		template::assign('order_list',order::order_list('tour',$pid));
		template::display('../admin/order-tour-list.html');
	break;
	case 'order-cruise-list':
		template::assign('order_list',order::order_list('cruise',$pid));
		template::display('../admin/order-cruise-list.html');
	break;
	case 'order-cruise-cl':
		order::chuli($id,'cruise',$_GET['status'],$_GET['r']);
		template::assign('order_list',order::order_list('cruise',"处理成功."));
		template::assign('order_list',order::order_list('cruise',$pid));
		template::display('../admin/order-cruise-list.html');
	break;
	case 'order-tour-cl':
		print_r($_GET);
	break;
    case 'login':
        if(!admin::isAdminOnline()){
    		if(isset($_POST['user'])){
    		    if($_POST['user']!='' && $_POST['password']!=''){
					admin::adminlogin($_POST);
    		    }else{
    		    template::assign('errmsg','Sorry! Your name and the password is error.');
    			template::display('../admin/login.html');
    		    }
    		}else{
    			template::display('../admin/login.html');
    		}
          }else{
              template::display('../admin/main.html');
          }
    break;
    case 'logout':
        admin::adminlogout();
    break;
    case 'header':
        template::display('../admin/header.html');
    break;
    case 'menu':
        template::display('../admin/menu.html');
    break;
    case 'folding':
        template::display('../admin/folding.html');
    break;
    case 'system':
	template::assign('admin_name',$_SESSION['kona_admin']);
	template::assign('phpVersion',phpversion());
	template::assign('mysqlVersion',mysql_get_server_info());
	$gd_info = gd_info();
	template::assign('gdVersion',$gd_info['GD Version']);
	template::assign('webInfo',$_SERVER['SERVER_SOFTWARE']);
	template::assign('nowTime',date("Y-m-d h:i",time()));
        template::display('../admin/system.html');
    break;
    case 'setting':
        template::display('../admin/setting.html');
    break;
	case 'admin-list':
		template::assign('admin_list',admin::getUser());
		template::display('../admin/admin-list.html');
	break;
    case 'admin-add':
		if(isset($_POST['username']) && isset($_POST['pwd'])){
			admin::admin_add($_POST);
		}else{
			template::display('../admin/admin-add.html');
		}
    break;
	case 'admin-edit':
		if(admin::admin_edit($_POST)){
			$errmsg = "密码修改成功";
		}else{
			$errmsg = "修改失败，请联系konakona";
		}
		template::assign('errmsg',$errmsg);
		template::assign('admin_list',admin::getUser());
		template::display('../admin/admin-list.html');
	break;
	case 'admin-del':
		admin::delUser($id);
	break;
	case 'flight-list':
                page::set_Each_page(15);
		template::assign('flight_page',page::run($pid,'flight','admin.php?action=flight-list&p='));
		template::assign('flight_list',flight::flight_list($pid,false,15));
		template::display('../admin/flight-list.html');
	break;
	case 'flight-add':
		if(isset($_POST['name'])){
			flight::flight_add($_POST);
		}else{
			template::display('../admin/flight-add.html');
		}
	break;
	case 'flight-details':
		$result = flight::flight_details($id);
		$season_select =  flight::season_select($result['high_seasons']);
		template::assign('flight',$result);
		template::assign('season_select',$season_select);
		template::display('../admin/flight-edit.html');
	break;
	case 'flight-edit':
		flight::flight_edit($_POST);
	break;
	case 'flight-del':
		flight::flight_del($id);
	break;
	case 'cruise-list':
                page::set_Each_page(15);
		template::assign('cruise_page',page::run($pid,'cruise','admin.php?action=cruise-list&p='));
		template::assign('cruise_list',cruise::cruise_list($pid,15));
		template::display('../admin/cruise-list.html');
	break;
	case 'cruise-route-add':
		if($_POST['start']!=''){
			cruise::cruise_route_add($_POST);
		}else{
			template::display('../admin/cruise-route-add.html');
		}
	break;
	case 'cruise-add':
		if($_POST['flight']!=''){
			cruise::cruise_add($_POST);
		}else{
			template::assign('flight_list',flight::flight_list(0,false,100));//不会有超过100膄游轮吧
			template::assign('city_list',cruise::city_list());
			template::display('../admin/cruise-add.html');
		}
	break;
	case 'cruise-del':
		cruise::cruise_del($id);
	break;
	case 'cruise-edit':
		if(isset($_POST['flight'])){
			cruise::cruise_edit($_POST);
		}else{
			template::assign('city_list',cruise::city_list());
			template::assign('cruise_details',cruise::cruise_details($id));
			template::assign('flight_list',flight::flight_list(0,false,100));
			template::display('../admin/cruise-edit.html');
		}
	break;
	case 'comments-list':
		template::register_function('cutstr','k::cutstr');
		template::assign('comments_page',page::run($pid,'comments','admin.php?action=comments-list&p='));
		template::assign('comments',comments::comments_list($pid,false,10));
		template::display('../admin/comments-list.html');
	break;
	case 'comments-del':
		comments::comments_del($id);
	break;
}
